//
//  HeTongManagerDetailCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/9/9.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "HeTongManagerDetailCell.h"

@interface HeTongManagerDetailCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *noLab;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *companyLab;
@property (nonatomic, strong) UILabel *dateLab;
@property (nonatomic, strong) UILabel *dayLab;
@property (nonatomic, strong) UILabel *styleLab;

@end

@implementation HeTongManagerDetailCell

+ (instancetype)HeTongManagerDetailCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"HeTongManagerDetailCell";
    HeTongManagerDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[HeTongManagerDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 10, ScreenW - 30, 200)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        UILabel *noTitleLab = [UILabel new];
        noTitleLab.textColor = HexColor(0x9C9DB3);
        noTitleLab.font = [UIFont systemFontOfSize:14];
        noTitleLab.text = @"合同流水号：";
        [self.bgView addSubview:noTitleLab];
        [noTitleLab sizeToFit];
        CGFloat margin = (self.bgView.nim_height - 5 * noTitleLab.nim_height) * 0.16666666;
        noTitleLab.nim_top = margin;
        noTitleLab.nim_left = 15;
        
        UIButton *fuZhiBtn = [UIButton new];
        [fuZhiBtn setImage:[UIImage imageNamed:@"icon_ladingbill_erweima"] forState:0];
        fuZhiBtn.nim_width = 18;
        fuZhiBtn.nim_height = 18;
        fuZhiBtn.nim_left = self.bgView.nim_width - 15 - fuZhiBtn.nim_width;
        fuZhiBtn.nim_centerY = noTitleLab.nim_centerY;
        [fuZhiBtn addTarget:self action:@selector(fuZhiClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:fuZhiBtn];
        
        self.noLab = [[UILabel alloc] initWithFrame:CGRectMake(noTitleLab.nim_right + 10, noTitleLab.nim_top, fuZhiBtn.nim_left - (noTitleLab.nim_right + 10), noTitleLab.nim_height)];
        self.noLab.textColor = HexColor(0x2B2C44);
        self.noLab.font = BoldFontOfSize(14);
        self.noLab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.noLab];
        
        UILabel *nameTitleLab = [UILabel new];
        nameTitleLab.textColor = HexColor(0x9C9DB3);
        nameTitleLab.font = [UIFont systemFontOfSize:14];
        nameTitleLab.text = @"合同名称：";
        [self.bgView addSubview:nameTitleLab];
        [nameTitleLab sizeToFit];
        nameTitleLab.nim_left = noTitleLab.nim_left;
        nameTitleLab.nim_top = noTitleLab.nim_bottom + margin;
        
        self.nameLab = [[UILabel alloc] initWithFrame:CGRectMake(nameTitleLab.nim_right + 10, nameTitleLab.nim_top, self.bgView.nim_width - 15 - (nameTitleLab.nim_right + 10), nameTitleLab.nim_height)];
        self.nameLab.textColor = HexColor(0x2B2C44);
        self.nameLab.font = BoldFontOfSize(14);
        self.nameLab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.nameLab];
        
        UILabel *companyTitleLab = [UILabel new];
        companyTitleLab.textColor = HexColor(0x9C9DB3);
        companyTitleLab.font = [UIFont systemFontOfSize:14];
        companyTitleLab.text = @"承运方：";
        [self.bgView addSubview:companyTitleLab];
        [companyTitleLab sizeToFit];
        companyTitleLab.nim_left = nameTitleLab.nim_left;
        companyTitleLab.nim_top = nameTitleLab.nim_bottom + margin;
        
        self.companyLab = [[UILabel alloc] initWithFrame:CGRectMake(companyTitleLab.nim_right + 10, companyTitleLab.nim_top, self.bgView.nim_width - 15 - (companyTitleLab.nim_right + 10), companyTitleLab.nim_height)];
        self.companyLab.textColor = HexColor(0x2B2C44);
        self.companyLab.font = BoldFontOfSize(14);
        self.companyLab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.companyLab];
        
        UILabel *dateTitleLab = [UILabel new];
        dateTitleLab.textColor = HexColor(0x9C9DB3);
        dateTitleLab.font = [UIFont systemFontOfSize:14];
        dateTitleLab.text = @"合同有效期：";
        [self.bgView addSubview:dateTitleLab];
        [dateTitleLab sizeToFit];
        dateTitleLab.nim_left = noTitleLab.nim_left;
        dateTitleLab.nim_top = companyTitleLab.nim_bottom + margin;
        
        self.dateLab = [[UILabel alloc] initWithFrame:CGRectMake(dateTitleLab.nim_right + 10, dateTitleLab.nim_top, self.bgView.nim_width - 15 - (dateTitleLab.nim_right + 10), dateTitleLab.nim_height)];
        self.dateLab.textColor = HexColor(0x2B2C44);
        self.dateLab.font = BoldFontOfSize(14);
        self.dateLab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.dateLab];
        
        UILabel *dayTitleLab = [UILabel new];
        dayTitleLab.textColor = HexColor(0x9C9DB3);
        dayTitleLab.font = [UIFont systemFontOfSize:14];
        dayTitleLab.text = @"对账周期（天）：";
        [self.bgView addSubview:dayTitleLab];
        [dayTitleLab sizeToFit];
        dayTitleLab.nim_left = noTitleLab.nim_left;
        dayTitleLab.nim_top = dateTitleLab.nim_bottom + margin;
        
        self.dayLab = [[UILabel alloc] initWithFrame:CGRectMake(dayTitleLab.nim_right + 10, dayTitleLab.nim_top, self.bgView.nim_width - 15 - (dayTitleLab.nim_right + 10), dayTitleLab.nim_height)];
        self.dayLab.textColor = HexColor(0x2B2C44);
        self.dayLab.font = BoldFontOfSize(14);
        self.dayLab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.dayLab];
        
        UILabel *styleTitleLab = [UILabel new];
        styleTitleLab.textColor = HexColor(0x9C9DB3);
        styleTitleLab.font = [UIFont systemFontOfSize:14];
        styleTitleLab.text = @"结算方式：";
        [self.bgView addSubview:styleTitleLab];
        [styleTitleLab sizeToFit];
        styleTitleLab.nim_left = noTitleLab.nim_left;
        styleTitleLab.nim_top = dayTitleLab.nim_bottom + margin;
        
        self.styleLab = [[UILabel alloc] initWithFrame:CGRectMake(styleTitleLab.nim_right + 10, styleTitleLab.nim_top, self.bgView.nim_width - 15 - (styleTitleLab.nim_right + 10), styleTitleLab.nim_height)];
        self.styleLab.textColor = HexColor(0x2B2C44);
        self.styleLab.font = BoldFontOfSize(14);
        self.styleLab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.styleLab];
        
        UIButton *listBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.nim_left, self.bgView.nim_bottom + 10, self.bgView.nim_width, 50)];
        listBtn.backgroundColor = HexColor(0xffffff);
        listBtn.layer.masksToBounds = YES;
        listBtn.layer.cornerRadius = 6;
        [listBtn setTitle:@"查看报价单" forState:0];
        [listBtn setTitleColor:Color_ThemeColor forState:0];
        listBtn.titleLabel.font = BoldFontOfSize(16);
        [listBtn setImage:[UIImage imageNamed:@"icon_form"] forState:0];
        [listBtn addTarget:self action:@selector(listClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:listBtn];
        
        self.height = listBtn.nim_bottom;
    }
    return self;
}

- (void)listClick {
    if (self.lookClock) {
        self.lookClock();
    }
}

- (void)fuZhiClick {
    
}

-(void)setModel:(HeTongManagerModel *)model {
    _model = model;
    self.noLab.text = model.constract_sn;
    self.nameLab.text = model.constract_name;
    self.companyLab.text = model.name;
    self.dateLab.text = [NSString stringWithFormat:@"%@ - %@",model.startTime,model.endTime];
    self.dayLab.text = model.cycle;
    self.styleLab.text = model.p_name;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
